<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2018/8/9
 * Time: 15:56
 */

namespace app\api\model;


use think\Model;

class ClassroomOrder extends Model
{
    /**
     * 查询订单列表&订单详情
     * @param string $order_id  订单ID
     * @param $field  查询字段
     * @param $page  当前页码
     * @param int $pageSize   每页显示条数
     * @return array|false|\PDOStatement|string|\think\Collection|Model
     */
    public function myOrderList($where, $order_id = '', $field, $page, $pageSize = 10){
        if($order_id == ''){
            $pageNum = $page - 1;
            $orderInfo = $this->alias('o')
                ->join('up_classroom uc', 'uc.id = o.classroom_id', 'left')
                ->where($where)
                ->field($field)
                ->order('o.order_id desc')
                ->limit($pageNum * $pageSize, $pageSize)
                ->select();
        }else{
            $orderInfo = $this->alias('o')
                ->join('up_classroom uc', 'uc.id = o.classroom_id', 'left')
                ->where($where)
                ->field($field)
                ->find();
        }
            return $orderInfo;
    }
    
    /**
     * 删除订单
     * @param $order_id  订单ID
     * @return int
     */
    public function delOrder($order_id){
        $res = $this->where('order_id', $order_id)->delete();
        return $res;
    }
}